package com.voxel.sense.infomsg.utils.marker.cluster.strategy;

import com.amap.api.maps.model.LatLng;
import com.voxel.sense.infomsg.utils.cover.EntityConvertStrategy;
import com.voxel.sense.infomsg.utils.marker.cluster.data.ClusterItem;
import com.voxel.sense.infomsg.utils.marker.cluster.data.RegionItem;

import java.util.ArrayList;
import java.util.List;

import cyy.example.com.facotry.model.api.response.WarningFirmEntity;

/**
 * 设备异常数据转换
 * Created by ChenYiYao on 2018/6/6.
 */
public class FacilityAbnorDataConvertStrategy implements EntityConvertStrategy<ClusterItem, WarningFirmEntity.UnusualCompanyBean> {
    boolean isVisible = true;

    @Override
    public List<ClusterItem> convertEntity(List<WarningFirmEntity.UnusualCompanyBean> list) {

        return convertEntity(list, "");
    }

    @Override
    public List<ClusterItem> convertEntity(List<WarningFirmEntity.UnusualCompanyBean> list, String type) {
        if (list != null) {
            List<ClusterItem> regionItems = new ArrayList<>();
            convertFirmTypeNor(list, regionItems, type);
            return regionItems;
        }
        return null;
    }


    private void convertFirmTypeNor(List<WarningFirmEntity.UnusualCompanyBean> entyt, List<ClusterItem> regionItems, String type) {
        for (WarningFirmEntity.UnusualCompanyBean bean : entyt) {
            try {
                double latitude = Double.parseDouble(bean.getLatitude());
                double longitude = Double.parseDouble(bean.getLongitude());
                RegionItem item = null;
                item = new RegionItem(new LatLng(latitude, longitude), type, bean, isVisible);
                regionItems.add(item);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
    }

    public boolean isVisible() {
        return isVisible;
    }

    public void setVisible(boolean visible) {
        isVisible = visible;
    }
}
